function buildListDomOfMobileByDataList(options) {
        var dataList=options.dataList||[];
        var imgBasePath=options.imgBasePath||"./";
        var pageTargetType=options.pageTargetType||"_blank";
        var $loading=$(options.loadingSelector);
        var arrTemp=[];
        var dataCount=0;
        $.each(dataList,function (idx, obj) {
            dataCount++;
            var hoseTypeText="";
            hoseTypeText+=obj['houseTypeOne']===""?"":obj['houseTypeOne']+"室";
            hoseTypeText+=obj['houseTypeTwo']===""?"&nbsp;":obj['houseTypeTwo']+"厅&nbsp;";
            var houseFloorText="";
            houseFloorText+=obj['houseFloor']===""?"":obj['houseFloor']+"层&nbsp;/&nbsp;共";
            houseFloorText+=obj['houseFloorTotal']===""?"":obj['houseFloorTotal']+"层&nbsp;&nbsp;";
            houseFloorText+=obj['livingCondition']===""?"":obj['livingCondition'];
            // houseFloorText='1层&nbsp;/共6层&nbsp;&nbsp;自住';
            var houseAreaText=obj['houseFloorArea']===""?"":obj['houseFloorArea']+"m²&nbsp;&nbsp;";//建筑面积
            var orientation=obj['houseOrientations']?obj['houseOrientations']:"";//朝向
            var typicalDom=hoseTypeText+houseAreaText+orientation;
            var addressDom=obj['houseAddress']?'<span class="address">&nbsp;'+obj['houseAddress']+'</span>':"";
            var listingPriceDom=obj['quotePrice']===""? "" : '<i class="total-price">'+obj['quotePrice']+'万</i>';
            // var unitPriceDom=obj['unitPrice']===""?"" : '<span class="unit-price">'+obj['unitPrice']+'元/m²</span>';
            var unitPriceDom='<span class="unit-price">'+obj['unitPrice']+'元/m²</span>';
            var tempDom='<li class="panel">'+'<div class="houseTitle"><h5>'+obj['villageName']+obj['decorationCondition']+obj['houseType']+'</h5><p class="auditState"><span>'+obj['houseStatus']+'</span></p></div>'+
                                '<a href="javascript:;">'+
                                    '<div class="cover-image"><img src="'+imgBasePath+obj['housePhotos'].split(',')[0]+'"></div>'+
                                    '<div class="house-info">'+'<div>'+houseFloorText+listingPriceDom+'</div>'+'<div class="clearfix"><div>'+typicalDom+'</div>'+unitPriceDom+'</div>'+
                                        '<p class="clearfix">'+addressDom+'</p>'+
                                    '</div>'+
                                '</a>'+
                            '</li>';
            arrTemp.push(tempDom) ;
        });
        $loading.length>0?(dataList.length && dataList.length<10 || dataCount<10 ? $loading.text("已经没有更多信息了").show():$loading.text("").hide()):"无点击加载选择器";
        return arrTemp.join("");
    };
$(function () {
    var data=common.getLocalData('H5-agentInfo');
    var token=common.getToken();
    var id=data.id;
    var $houseSaleListPanel=$("#house-saleList");
    var $checkStatus=$(".check-status");
    var globalHost=common.globalHost;
    var listPort=common.getHouseListPort;
    var getCurrentWeekHouseCount=common.getCurrentWeekHouseCount;
    var getHouseCountByAgent=common.getHouseCountByAgent;
    var documentHeight=0;
    var windowHeight=0;
    var $resMsg=$("#res-msg");
    var sendData={
        pageNum:1,
        numPerPage:10,
        status:'AVAILABLE',
        token:token,
        agentId:id
    };
    var $historyNum=$('#history-num');
    var $weekNum=$('#week-num');
    var $loadingFail=$('.loading-fail');
    var numWeekUrl=globalHost+getCurrentWeekHouseCount;
    var numTotalUrl=globalHost+getHouseCountByAgent;
    var url=globalHost+listPort;
    var sendMain={
        agentId:id,
        token:token,
    };
    requestDataListAjax({
        url:numTotalUrl,
        sendData:sendMain,
        callback:function(data){
            if(!!data && data['code']=="0"){
                data=data.res.data.count;
            }; 
            $historyNum.html(data);
        }
    });
    requestDataListAjax({
        url:numWeekUrl,
        sendData:sendMain,
        callback:function(data){
            if(!!data && data['code']=="0"){
                data=data.res.data.count;
            }; 
            $weekNum.html(data);
        }
    });
    requestDataListAjax({
        url:url,
        sendData:sendData,
        callback:function(data){
            $resMsg.text("").hide();
            $loadingFail.hide();
            if(!!data && data['code']=="0"){
                var totalNum=data.res.data.page.recordCount;
                if(totalNum==0){
                    $loadingFail.show();
                    $sideNav.hide();
                }else{
                    data=data.res.data.record;
                    $sideNav.show();
                    if(!data.length){
                        $resMsg.text("已经没有更多信息了").show();
                        flag=false;
                    }else{
                        var responseDom=buildListDomOfMobileByDataList({
                            loadingSelector:$resMsg,
                            imgBasePath:common.imageHost,
                            pageTargetType:"_self",
                            dataList:data
                        });
                        $houseSaleListPanel.append(responseDom);
                        documentHeight=$(document).height();
                        sendData.pageNum++;
                    };
                };
            };
        }
    });
     // alert(requestDataListAjax)
    var $sideNav=$('#side-nav');
    var timeout = false;   
    var flag=true; 
    $(window).on("scroll",function (e) {
        windowHeight=$(window).height();
        $sideNav.removeClass('remove-scroll').addClass('scroll');
         if (timeout){clearTimeout(timeout);}   
            timeout = setTimeout(function(){   
                $sideNav.removeClass('scroll').addClass('remove-scroll');
        },100);   
        if($(this).scrollTop()+windowHeight==documentHeight){
            if(flag){
                requestDataListAjax({
                    url:url,
                    sendData:sendData,
                    callback:function(data){
                        $resMsg.text("").hide();
                        $loadingFail.hide();
                        if(!!data && data['code']=="0"){
                            var totalNum=data.res.data.page.recordCount;
                            if(totalNum===0){
                                $loadingFail.show();
                                $sideNav.hide();
                            }else{
                                data=data.res.data.record;
                                $sideNav.show();
                                if(!data.length){
                                    $resMsg.text("已经没有更多信息了").show();
                                    flag=false;
                                }else{
                                    var responseDom=buildListDomOfMobileByDataList({
                                        loadingSelector:$resMsg,
                                        imgBasePath:common.imageHost,
                                        pageTargetType:"_self",
                                        dataList:data
                                    });
                                    $houseSaleListPanel.append(responseDom);
                                    documentHeight=$(document).height();
                                    sendData.pageNum++;
                                };
                            };
                        };
                    }
                });
            }  
        }
    });
    function requestDataListAjax(options) {
        var url=options.url;
        var sendData=options.sendData;
        var callback=options.callback;
        $.ajax({
            data:sendData,
            type: "POST",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            dataType:"json",
            url:url,
            success:function(data){
                if(typeof data==="string"){
                    data=JSON.parse(data);
                };
                if(data.code==101 ||data.code==102){
                    console.log("token为空或者token失效");
                    window.location.href='login.html';
                };  
                callback(data);         
            },
            timeout:30000,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                common.errDialog("网络不畅，请稍后重试");
            }
        });
    };
});